<?php

namespace app\api\model\hotel;

use think\Model;


class HotelOrderInvoice extends Model
{





    // 表名
    protected $name = 'hotel_order_invoice';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'open_time_text'
    ];




    public function getStatusList()
    {
        return [0 => '开票中',1=>'已开票',2=>'已驳回'];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['status'] ?? '');
        $list = $this->getStatusList();
        return $list[$value] ?? '';
    }


    public function getOpenTimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['open_time'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

}
